package com.tensquare.search.controller;

import com.tensquare.search.pojo.Article;
import com.tensquare.search.service.ArticleSearchService;
import entity.PageResult;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by WF on 2019/9/20 10:09
 */
@RestController
@RequestMapping("/article")
@CrossOrigin
public class ArticleSearchController {
    @Autowired
    private ArticleSearchService articleSearchService;
    //1.添加文章
    @PostMapping
    public Result add(@RequestBody Article article){
        //1.1)添加文章
        articleSearchService.add(article);
        //1.2)返回
        return new Result(true,StatusCode.OK,"添加文章成功！");
    }

    //2.根据标题及内容进行分页查询
    @GetMapping("search/{keywords}/{page}/{size}")
    public Result findByTitelAndContentLike(@PathVariable String keywords,@PathVariable int page,@PathVariable int size){
        //2.1)根据关键字及分页参数查询得到内容
        PageResult<Article> articleResult = articleSearchService.findByTitelAndContentLike(keywords,page,size);
        //2.2)返回结果
        return new Result(true,StatusCode.OK,"查询标题及内容成功！" ,articleResult);
    }
}
